package com.shujia.mr.partitioner;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class PartitionerMapper extends Mapper<LongWritable, Text, Text, Text> {
    /*
        从students.txt中读取每一行数据，将学生ID作为Key，其他数据作为Value写出到Reduce中，
                并且将年龄进行分区
     */

    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, Text>.Context context) throws IOException, InterruptedException {
        String oneLine = value.toString();
        String[] cols = oneLine.split(",");
        String id = cols[0];

        // 将数据写出
        context.write(new Text(id), new Text(oneLine));
    }
}
